<template>
  <div style="background-color: #fff">
<!--    <div style="position: sticky;top: 0;z-index: 99">-->
<!--      <Myheader></Myheader>-->
<!--    </div>-->
    <div
      style="background:url('https://www.tsinghua.org.cn/dfiles/18365/publish/alumni/index0/images/xwzx_bg.jpg');padding:10px 20px;"
    >
      <div
        style="color: #ed6d51;font-size: 30px;padding: 20px 20px;text-align: center;"
      >
        校友信息
      </div>
      <div class="filter-input">
        <div>
          <el-select
            v-model="filterForm.xingming"
            filterable
            placeholder="请输入学生姓名"
          >
            <el-option
              v-for="item in allStudentList"
              :key="item.xuehao"
              :label="item.xingming"
              :value="item.xingming"
            >
            </el-option>
          </el-select>

          <el-input placeholder="请输入学生学号" v-model="filterForm.xuehao">
          </el-input>
          <el-button type="danger" plain @click="handleSearch">搜索</el-button>
          <el-button type="danger" plain @click="handleReset">重置</el-button>
        </div>
      </div>
      <div class="mainContent">
        <template v-if="isShow">
          <el-timeline>
            <el-timeline-item
              v-for="(data, index) in dataList"
              :key="index"
              placement="top"
              color="#89131a"
              size="large"
              :timestamp="data.nianfen"
            >
              <div style="display: flex; justify-content: space-between;">
                <span
                  v-for="(item, index) in data.xuelilist"
                  style="margin-right: 36px;"
                  :key="index"
                  @click="handleXueLi(data.nianfen, item)"
                >
                  <a href="#">{{ item }}</a></span
                >
              </div>
            </el-timeline-item>
          </el-timeline>
        </template>

        <template v-else>
          <div>
            <el-row :gutter="20">
              <el-col
                v-for="(item, index) in studentList"
                :key="index"
                :span="6"
                style="margin-bottom: 30px;"

              >
            <div @click="viewStudentDetail(item.xuehao)">
              <img
              :src="`http://localhost:8087/dev-api${item.benrenzhaopian}`"
                  class="image"
                />
                <div style="margin-top: 12px;">

                  <div class="studentInfo">
                    <p class="time">姓名：{{ item.xingming }}</p>
                    <p class="time">学号：{{ item.xuehao }}</p>
                    <p class="time">班级：{{ item.banjimingcheng }}</p>
                  </div>
                </div>
            </div>
              </el-col>
            </el-row>
          </div>
        </template>
      </div>

      <!-- <div style="margin: 30px  0;display: flex;justify-content: flex-end;">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          layout="total,prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div> -->
    </div>

<!--    <div>-->
<!--      <MyBottom></MyBottom>-->
<!--    </div>-->
  </div>
</template>

<script>
import Myheader from "./header.vue";
import MyBottom from "./bottom.vue";
import { getNianFen, getStudent } from "@/api";
export default {
  name: "alumnus",
  data() {
    return {
      studentList: [],
      allStudentList: [],
      total: 100,
      isShow: true,
      dataList: [],
      filterForm: {
        name: "",
        personCode: ""
      }
    };
  },
  components: {
    Myheader,
    MyBottom
  },
  methods: {
    handleXueLi(nianfen, xueli) {
      console.log("1", nianfen, xueli);

      this.$router.push({
        path: "/classList",
        query: {
          nianfen,
          xueli
        }
      });
    },

    async handleSearch() {
      this.isShow = false;

      await getStudent(this.filterForm)
        .then(res => {
          console.log("res: ", res);

          this.studentList = res.data;
        })
        .catch(err => {
          console.log("err", err);
        });
    },
    handleReset() {
      this.isShow = true;
    },
    viewStudentDetail(xuehao) {
      console.log("xuehao: ", xuehao);
      this.$router.push({
      path:'/studentDetail',
      query:{
          xuehao: xuehao
        }
      })
    }
  },
  mounted() {
    getNianFen()
      .then(res => {
        console.log("res: ", res);
        this.dataList = res.data;
      })
      .catch(err => {
        console.log("err: ", err);
      });
    getStudent(this.filterForm)
      .then(res => {
        this.allStudentList = res.data
      })
      .catch(err => {
        console.log("err", err);
      });
  }
};
</script>

<style scoped>
.mainContent {
  width: 100%;
  margin-top: 36px;

}
.image {
  width: 100px;
  display: block;
}
.studentInfo {
  p {
    font-size: 12px;
  }
}
.filter-input {
  display: flex;
  justify-content: center;
  width: 100%;
}
/deep/ .el-input {
  width: 150px;
}
/deep/ .el-image {
  width: 238px;
  height: 160px;
  overflow: hidden;
}
/deep/ .el-image__inner:hover {
  transform: scale(1.2);
  transition: transform 0.5s ease-in-out;
}
.card {
  background-color: white;
  padding: 10px;
  text-align: left;
  line-height: 1.7;
  font-size: 14px;
}
.c-item {
  cursor: pointer;
  width: 300px;
  margin-bottom: 20px;
}
.c-item:hover {
  animation: colorChange 3s forwards; /* 添加动画效果 */
  transition: transform 0.5s ease-in-out;
  box-shadow: 6px 0 1px rgb(147, 23, 31);
}

@keyframes colorChange {
  0% {
    background-image: linear-gradient(to right, #93171f 0%, #93171f 0%);
  }
  100% {
    background-image: linear-gradient(to right, #93171f 0%, #93171f 100%);
  }
}
.container {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

/deep/ .el-image {
  width: 100%;
}

/deep/ .el-image__inner {
  width: 100%;
}
</style>
